public class test13 {
    public String minWindow(String s, String t) {
        int[] need = new int[128];
        int[] window = new int[128];
        for(int i = 0;i<t.length();i++){
            need[t.charAt(i)]++;
        }

        int right = 0,left = 0;
        String res = "";
        int count = 0;//有效数字个数
        int minLen = s.length()+1;//子串最小长度
        while(right<s.length()){
            char ch = s.charAt(right);
            window[ch]++;
            if(need[ch]>0 && need[ch]>=window[ch]){
                count++;
            }
            while(t.length()==count){
                //移动窗口
                char rem = s.charAt(left);
                if(need[rem]>0 && need[rem]>=window[rem]){
                    count--;
                }
                if(right-left+1<minLen){
                    minLen = right-left+1;
                    res = s.substring(left,right+1);
                }
                left++;
                window[rem]--;
            }
            right++;
        }
        return res;
    }
}
